package org.example.leetCode;

public class matrixReshape {
    public int[][] matrixReshape(int[][] mat, int r, int c) {
        if(mat.length*mat[0].length!=r*c){
            return mat;
        }
        int[][] ints = new int[r][c];
        int count =0;
        for (int i = 0;i<r;i++){
            for (int j =0;j<c;j++){
                ints[i][j]=mat[count/mat[0].length][count%mat[0].length];
                count++;
            }
        }
        return ints;
    }
}
